<template>
	<view class="set-up">
		<!-- 头部 -->
		<!-- #ifndef MP-WEIXIN -->
		<public-header :title="title"></public-header>
		<view class="hei_100"></view>
		 <!-- #endif -->
		<!-- end -->
		
		<!-- 列表 -->
		<view class="list padd_32">
			<!-- #ifdef MP-WEIXIN -->
			<view class="clearfix" @click="setting()">
				授权管理
				<image src="/static/images/r-arrow.png" class="fr" mode="widthFix"></image>
			</view>
			<view class="clearfix" @click="subscribe()">
				订阅消息
				<image src="/static/images/r-arrow.png" class="fr" mode="widthFix"></image>
			</view>
			<!-- #endif -->
			<navigator url="/pageageA/pages/problem/online">
				<view class="clearfix">
					问题反馈
					<image src="/static/images/r-arrow.png" class="fr" mode="widthFix"></image>
				</view>				
			</navigator>
			<navigator url="/pageageA/pages/register/bindPhone">
				<view class="clearfix">
					绑定/修改手机号码
					<image src="/static/images/r-arrow.png" class="fr" mode="widthFix"></image>
				</view>				
			</navigator>
			<navigator url="/pageageA/pages/register/retrieve">
				<view class="clearfix">
					修改登录密码
					<image src="/static/images/r-arrow.png" class="fr" mode="widthFix"></image>
				</view>				
			</navigator>
			<view>
				<!-- <view class="clearfix">
					<view class="botton">
						<button class="wxlogin" open-type="getUserInfo"  @getuserinfo="bindGetUserInfo()">微信绑定</button>
					</view>
					<image src="/static/images/r-arrow.png" class="fr" mode="widthFix"></image>
				</view> -->
				<!-- <button type="primary" open-type="getUserInfo">页面主操作 Normal</button> -->
			</view>
		</view>
		<!-- end -->
		
		<!-- 按钮 -->
		<view class="btn" @click="exit">退出登录</view>
		<!-- end -->
	</view>
</template>

<script>
import PublicHeader from '@/components/PublicHeader.vue';
import { mapState, mapMutations } from 'vuex';
export default {
	components: {
		PublicHeader,
		options: {
		    addGlobalClass: true,
		  }
	},
	computed: mapState(['hasLogin', 'uerInfo']),
	data() {
		return {
			title: '设置'
		};
	},
	methods: {
		...mapMutations(['logout']),
		setting() {
			uni.openSetting({
			  success(res) {
			    console.log(res.authSetting)
			  }
			})
		},
		subscribe() {
			let _this = this
			uni.requestSubscribeMessage({
				tmplIds: ['AqehYpGhzUSTjNCp7lr9owJQt0K9PvZE3Ayke_O6uEo', 'SB5tr6mcmw2mqqxabYG0hR4tEaEC4wsJ_XpAYFriE1Y'],
				success(res) {
					console.log(res)
					uni.getProvider({
					  service: 'oauth',
					  success: function (res) {
						if (~res.provider.indexOf('weixin')) {
							uni.login({
								provider: 'weixin',
								success: (loginRes) => {
									uni.getUserInfo({
										provider: 'weixin',
										success: (info) => {//这里请求接口
											console.log('用户信息:',info)
											console.log('微信code:',loginRes)
											_this.$http.get('/WeChat/MiniProgram/get/Access/Key/' + loginRes.code, {
												appid: 'wx74c82575ffce4b03',
												secret:'3a929a22d8977914f8f5029d4d14726f'
											}).
											then(function (res) {
												console.log('openid', res)
												_this.$http.get('/wxapplet/push', {
													openid: res.data.openid,
													medolId:'AqehYpGhzUSTjNCp7lr9owJQt0K9PvZE3Ayke_O6uEo'
												}).
												then(function (res) {
												}).catch(function (error) {
													console.log(error);
												});
											}).catch(function (error) {
												console.log(error);
											});
										},
										fail: () => {
											uni.showToast({title:"微信登录授权失败",icon:"none"});
										}
									})
								},
								fail: () => {
									uni.showToast({title:"微信登录授权失败",icon:"none"});
								}
							})
						}else{
							uni.showToast({
								title: '请先安装微信或升级版本',
								icon:"none"
							});
						}
					  }
					});
				},
				fail(res) {
					console.log(res)
				},
			})
		},
		bindGetUserInfo(e) {
			// #ifdef MP-WEIXIN
			let _this = this
			uni.getProvider({
			  service: 'oauth',
			  success: function (res) {
				if (~res.provider.indexOf('weixin')) {
					uni.login({
						provider: 'weixin',
						success: (loginRes) => {
							uni.getUserInfo({
								provider: 'weixin',
								success: (info) => {//这里请求接口
									console.log('用户信息:',info)
									console.log('微信code:',loginRes)
									_this.weixin(loginRes)
								},
								fail: () => {
									uni.showToast({title:"微信登录授权失败",icon:"none"});
								}
							})
						},
						fail: () => {
							uni.showToast({title:"微信登录授权失败",icon:"none"});
						}
					})
					
				}else{
					uni.showToast({
						title: '请先安装微信或升级版本',
						icon:"none"
					});
				}
			  }
			});
			//#endif
		},
		weixin(loginRes) {
			let _this = this
			_this.$http.get('/WeChat/MiniProgram/get/Access/Key/' + loginRes.code, {
				appid: 'wx74c82575ffce4b03',
				secret:'3a929a22d8977914f8f5029d4d14726f'
			}).
			then(function (res) {
				_this.$http.post('/login/mandate', {
					userId: _this.uerInfo.userId,
					openid: res.data.openid,
					weiXinCard: res.data.openid
				}).
				then(function (response) {
					if (response.success) {
						uni.showToast({
							icon: 'none',
							position: 'bottom',
							title: '绑定成功'
						});
					}
				}).catch(function (error) {
					console.log(error);
				});
			}).catch(function (error) {
				console.log(error);
			});
		},
		exit() {
			var _this = this
			uni.showModal({
			    title: '',
			    content: '确定退出当前账号',
				cancelColor: '#57BFFF',
				confirmColor: '#57BFFF',
			    success: function (res) {
			        if (res.confirm) {
						_this.logout()
			        } else if (res.cancel) {
			            console.log('用户点击取消');
			        }
			    }
			});
		},
	},
};
</script>

<style scoped lang="scss">
.list .clearfix{
	height: 100rpx;
	font-size: 34rpx;
	color: #666;
	line-height: 100rpx;
	border-bottom: 1rpx solid #DFDFDF;
}
.list view .fr{
	width: 13rpx;
	margin-top: 42rpx;
}
.btn{
	font-size: 36rpx;
	color: #fff;
	width: 686rpx;
	height: 100rpx;
	line-height: 100rpx;
	text-align: center;
	border-radius: 10rpx;
	background-color: #FF7971;
	box-shadow:0px 4px 20px 0px #FF7971;
	position: fixed;
	bottom: 40rpx;
	left: 32rpx;
}
/* #ifndef MP-WEIXIN */
.botton{
	float: left;
	width: 300rpx;
	height: 100%;
	/* margin-top: 30rpx; */
	padding: 0!important;
	line-height: 1;
	color: #666!important;
}
/* #endif */
/* #ifdef MP-WEIXIN */
.botton{
	float: left;
	width: 300rpx;
	height: 100%;
	margin-top: 30rpx;
	padding: 0!important;
	line-height: 1;
	color: #666!important;
}
/* #endif */
.wxlogin{
	padding: 0!important;
	float: left;
	border: none !important;
	background-color: #FFFFFF;
	color: #666!important;
	height: 60rpx;
	line-height: 1;
}
uni-button{
	margin-top: 30rpx;
	padding: 0;
	line-height: 1;
	color: #666!important;
}
.wxlogin:after{
	border: none !important;
	color: #666!important;
}
</style>
